package cn.iocoder.yudao.module.system.controller.admin.examscore.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;

/**
 * 扩展的学生成绩导入 Excel VO
 * 支持新的Excel格式，包含更多的排名和等级信息
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExtendedExamScoreImportExcelVO {

    /**
     * 考试ID（导入时设置）
     */
    private Long examId;

    /**
     * 学生ID（导入时设置）
     */
    private Long studentId;

    /**
     * 班级ID（导入时设置）
     */
    private Long classId;

    // ========== 基础信息 ==========
    
    @ExcelProperty("准考证号")
    private String examNo;

    @ExcelProperty("班级")
    @NotBlank(message = "班级不能为空")
    private String className;

    @ExcelProperty("姓名")
    @NotBlank(message = "姓名不能为空")
    private String studentName;

    @ExcelProperty("选考科目")
    private String subjectCombination;

    // ========== 总分信息 ==========
    
    @ExcelProperty("总分")
    private BigDecimal totalScore;

    @ExcelProperty("原始分")
    private BigDecimal totalOriginalScore;

    @ExcelProperty("等级")
    private String totalGradeLevel;

    @ExcelProperty("联考名次")
    private Integer totalUnionRank;

    @ExcelProperty("联考方向名次")
    private Integer totalUnionDirectionRank;

    @ExcelProperty("联考选考名次")
    private Integer totalUnionSubjectRank;

    @ExcelProperty("校次")
    private Integer schoolRank;

    @ExcelProperty("校方向名次")
    private Integer schoolDirectionRank;

    @ExcelProperty("校选考名次")
    private Integer schoolSubjectRank;

    @ExcelProperty("班次")
    private Integer classRank;

    @ExcelProperty("班方向名次")
    private Integer classDirectionRank;

    @ExcelProperty("班选考名次")
    private Integer classSubjectRank;

    // ========== 选考总分 ==========
    
    @ExcelProperty("选考总分")
    private BigDecimal subjectTotalScore;

    @ExcelProperty("选考原始分")
    private BigDecimal subjectTotalOriginalScore;

    @ExcelProperty("选考等级")
    private String subjectTotalGradeLevel;

    @ExcelProperty("选考联考名次")
    private Integer subjectTotalUnionRank;

    @ExcelProperty("选考联考方向名次")
    private Integer subjectTotalUnionDirectionRank;

    @ExcelProperty("选考联考选考名次")
    private Integer subjectTotalUnionSubjectRank;

    @ExcelProperty("选考校次")
    private Integer subjectTotalSchoolRank;

    @ExcelProperty("选考校方向名次")
    private Integer subjectTotalSchoolDirectionRank;

    @ExcelProperty("选考校选考名次")
    private Integer subjectTotalSchoolSubjectRank;

    @ExcelProperty("选考班次")
    private Integer subjectTotalClassRank;

    @ExcelProperty("选考班方向名次")
    private Integer subjectTotalClassDirectionRank;

    @ExcelProperty("选考班选考名次")
    private Integer subjectTotalClassSubjectRank;

    // ========== 方向总分 ==========
    
    @ExcelProperty("方向总分")
    private BigDecimal directionTotalScore;

    @ExcelProperty("方向联考名次")
    private Integer directionTotalUnionRank;

    @ExcelProperty("方向联考方向名次")
    private Integer directionTotalUnionDirectionRank;

    @ExcelProperty("方向联考选考名次")
    private Integer directionTotalUnionSubjectRank;

    @ExcelProperty("方向校次")
    private Integer directionTotalSchoolRank;

    @ExcelProperty("方向校方向名次")
    private Integer directionTotalSchoolDirectionRank;

    @ExcelProperty("方向校选考名次")
    private Integer directionTotalSchoolSubjectRank;

    @ExcelProperty("方向班次")
    private Integer directionTotalClassRank;

    @ExcelProperty("方向班方向名次")
    private Integer directionTotalClassDirectionRank;

    @ExcelProperty("方向班选考名次")
    private Integer directionTotalClassSubjectRank;

    // ========== 主科总分 ==========
    
    @ExcelProperty("主科总分")
    private BigDecimal mainSubjectTotalScore;

    @ExcelProperty("主科联考名次")
    private Integer mainSubjectTotalUnionRank;

    @ExcelProperty("主科联考方向名次")
    private Integer mainSubjectTotalUnionDirectionRank;

    @ExcelProperty("主科联考选考名次")
    private Integer mainSubjectTotalUnionSubjectRank;

    @ExcelProperty("主科校次")
    private Integer mainSubjectTotalSchoolRank;

    @ExcelProperty("主科校方向名次")
    private Integer mainSubjectTotalSchoolDirectionRank;

    @ExcelProperty("主科校选考名次")
    private Integer mainSubjectTotalSchoolSubjectRank;

    @ExcelProperty("主科班次")
    private Integer mainSubjectTotalClassRank;

    @ExcelProperty("主科班方向名次")
    private Integer mainSubjectTotalClassDirectionRank;

    @ExcelProperty("主科班选考名次")
    private Integer mainSubjectTotalClassSubjectRank;

    // ========== 语文成绩 ==========
    
    @ExcelProperty("语文")
    private BigDecimal chineseScore;

    @ExcelProperty("语文联考名次")
    private Integer chineseUnionRank;

    @ExcelProperty("语文联考方向名次")
    private Integer chineseUnionDirectionRank;

    @ExcelProperty("语文联考选考名次")
    private Integer chineseUnionSubjectRank;

    @ExcelProperty("语文校次")
    private Integer chineseSchoolRank;

    @ExcelProperty("语文校方向名次")
    private Integer chineseSchoolDirectionRank;

    @ExcelProperty("语文校选考名次")
    private Integer chineseSchoolSubjectRank;

    @ExcelProperty("语文班次")
    private Integer chineseClassRank;

    @ExcelProperty("语文班方向名次")
    private Integer chineseClassDirectionRank;

    @ExcelProperty("语文班选考名次")
    private Integer chineseClassSubjectRank;

    // ========== 数学成绩 ==========
    
    @ExcelProperty("数学")
    private BigDecimal mathScore;

    @ExcelProperty("数学联考名次")
    private Integer mathUnionRank;

    @ExcelProperty("数学联考方向名次")
    private Integer mathUnionDirectionRank;

    @ExcelProperty("数学联考选考名次")
    private Integer mathUnionSubjectRank;

    @ExcelProperty("数学校次")
    private Integer mathSchoolRank;

    @ExcelProperty("数学校方向名次")
    private Integer mathSchoolDirectionRank;

    @ExcelProperty("数学校选考名次")
    private Integer mathSchoolSubjectRank;

    @ExcelProperty("数学班次")
    private Integer mathClassRank;

    @ExcelProperty("数学班方向名次")
    private Integer mathClassDirectionRank;

    @ExcelProperty("数学班选考名次")
    private Integer mathClassSubjectRank;

    // ========== 英语成绩 ==========
    
    @ExcelProperty("英语")
    private BigDecimal englishScore;

    @ExcelProperty("英语联考名次")
    private Integer englishUnionRank;

    @ExcelProperty("英语联考方向名次")
    private Integer englishUnionDirectionRank;

    @ExcelProperty("英语联考选考名次")
    private Integer englishUnionSubjectRank;

    @ExcelProperty("英语校次")
    private Integer englishSchoolRank;

    @ExcelProperty("英语校方向名次")
    private Integer englishSchoolDirectionRank;

    @ExcelProperty("英语校选考名次")
    private Integer englishSchoolSubjectRank;

    @ExcelProperty("英语班次")
    private Integer englishClassRank;

    @ExcelProperty("英语班方向名次")
    private Integer englishClassDirectionRank;

    @ExcelProperty("英语班选考名次")
    private Integer englishClassSubjectRank;

    // ========== 物理成绩 ==========
    
    @ExcelProperty("物理")
    private BigDecimal physicsScore;

    @ExcelProperty("物理联考名次")
    private Integer physicsUnionRank;

    @ExcelProperty("物理联考方向名次")
    private Integer physicsUnionDirectionRank;

    @ExcelProperty("物理联考选考名次")
    private Integer physicsUnionSubjectRank;

    @ExcelProperty("物理校次")
    private Integer physicsSchoolRank;

    @ExcelProperty("物理校方向名次")
    private Integer physicsSchoolDirectionRank;

    @ExcelProperty("物理校选考名次")
    private Integer physicsSchoolSubjectRank;

    @ExcelProperty("物理班次")
    private Integer physicsClassRank;

    @ExcelProperty("物理班方向名次")
    private Integer physicsClassDirectionRank;

    @ExcelProperty("物理班选考名次")
    private Integer physicsClassSubjectRank;

    // ========== 化学成绩 ==========
    
    @ExcelProperty("化学")
    private BigDecimal chemistryScore;

    @ExcelProperty("化学原始分")
    private BigDecimal chemistryOriginalScore;

    @ExcelProperty("化学等级")
    private String chemistryGradeLevel;

    @ExcelProperty("化学联考名次")
    private Integer chemistryUnionRank;

    @ExcelProperty("化学联考方向名次")
    private Integer chemistryUnionDirectionRank;

    @ExcelProperty("化学联考选考名次")
    private Integer chemistryUnionSubjectRank;

    @ExcelProperty("化学校次")
    private Integer chemistrySchoolRank;

    @ExcelProperty("化学校方向名次")
    private Integer chemistrySchoolDirectionRank;

    @ExcelProperty("化学校选考名次")
    private Integer chemistrySchoolSubjectRank;

    @ExcelProperty("化学班次")
    private Integer chemistryClassRank;

    @ExcelProperty("化学班方向名次")
    private Integer chemistryClassDirectionRank;

    @ExcelProperty("化学班选考名次")
    private Integer chemistryClassSubjectRank;

    // ========== 生物成绩 ==========
    
    @ExcelProperty("生物")
    private BigDecimal biologyScore;

    @ExcelProperty("生物原始分")
    private BigDecimal biologyOriginalScore;

    @ExcelProperty("生物等级")
    private String biologyGradeLevel;

    @ExcelProperty("生物联考名次")
    private Integer biologyUnionRank;

    @ExcelProperty("生物联考方向名次")
    private Integer biologyUnionDirectionRank;

    @ExcelProperty("生物联考选考名次")
    private Integer biologyUnionSubjectRank;

    @ExcelProperty("生物校次")
    private Integer biologySchoolRank;

    @ExcelProperty("生物校方向名次")
    private Integer biologySchoolDirectionRank;

    @ExcelProperty("生物校选考名次")
    private Integer biologySchoolSubjectRank;

    @ExcelProperty("生物班次")
    private Integer biologyClassRank;

    @ExcelProperty("生物班方向名次")
    private Integer biologyClassDirectionRank;

    @ExcelProperty("生物班选考名次")
    private Integer biologyClassSubjectRank;

    // ========== 政治成绩 ==========
    
    @ExcelProperty("政治")
    private BigDecimal politicsScore;

    @ExcelProperty("政治原始分")
    private BigDecimal politicsOriginalScore;

    @ExcelProperty("政治等级")
    private String politicsGradeLevel;

    @ExcelProperty("政治联考名次")
    private Integer politicsUnionRank;

    @ExcelProperty("政治联考方向名次")
    private Integer politicsUnionDirectionRank;

    @ExcelProperty("政治联考选考名次")
    private Integer politicsUnionSubjectRank;

    @ExcelProperty("政治校次")
    private Integer politicsSchoolRank;

    @ExcelProperty("政治校方向名次")
    private Integer politicsSchoolDirectionRank;

    @ExcelProperty("政治校选考名次")
    private Integer politicsSchoolSubjectRank;

    @ExcelProperty("政治班次")
    private Integer politicsClassRank;

    @ExcelProperty("政治班方向名次")
    private Integer politicsClassDirectionRank;

    @ExcelProperty("政治班选考名次")
    private Integer politicsClassSubjectRank;

    // ========== 历史成绩 ==========
    
    @ExcelProperty("历史")
    private BigDecimal historyScore;

    @ExcelProperty("历史联考名次")
    private Integer historyUnionRank;

    @ExcelProperty("历史联考方向名次")
    private Integer historyUnionDirectionRank;

    @ExcelProperty("历史联考选考名次")
    private Integer historyUnionSubjectRank;

    @ExcelProperty("历史校次")
    private Integer historySchoolRank;

    @ExcelProperty("历史校方向名次")
    private Integer historySchoolDirectionRank;

    @ExcelProperty("历史校选考名次")
    private Integer historySchoolSubjectRank;

    @ExcelProperty("历史班次")
    private Integer historyClassRank;

    @ExcelProperty("历史班方向名次")
    private Integer historyClassDirectionRank;

    @ExcelProperty("历史班选考名次")
    private Integer historyClassSubjectRank;

    // ========== 地理成绩 ==========
    
    @ExcelProperty("地理")
    private BigDecimal geographyScore;

    @ExcelProperty("地理原始分")
    private BigDecimal geographyOriginalScore;

    @ExcelProperty("地理等级")
    private String geographyGradeLevel;

    @ExcelProperty("地理联考名次")
    private Integer geographyUnionRank;

    @ExcelProperty("地理联考方向名次")
    private Integer geographyUnionDirectionRank;

    @ExcelProperty("地理联考选考名次")
    private Integer geographyUnionSubjectRank;

    @ExcelProperty("地理校次")
    private Integer geographySchoolRank;

    @ExcelProperty("地理校方向名次")
    private Integer geographySchoolDirectionRank;

    @ExcelProperty("地理校选考名次")
    private Integer geographySchoolSubjectRank;

    @ExcelProperty("地理班次")
    private Integer geographyClassRank;

    @ExcelProperty("地理班方向名次")
    private Integer geographyClassDirectionRank;

    @ExcelProperty("地理班选考名次")
    private Integer geographyClassSubjectRank;

    // ========== 辅助方法 ==========

    /**
     * 获取学号（从准考证号中提取或使用默认规则）
     */
    public String getStudentNo() {
        if (examNo != null && !examNo.isEmpty()) {
            return examNo;
        }
        // 如果没有准考证号，可以根据班级和姓名生成学号
        return className + "_" + studentName;
    }

    /**
     * 检查数据完整性
     */
    public boolean isDataComplete() {
        return studentName != null && !studentName.isEmpty() &&
               className != null && !className.isEmpty();
    }

    /**
     * 转换为NewExamScoreImportExcelVO格式
     */
    public NewExamScoreImportExcelVO toNewExamScoreImportExcelVO() {
        return NewExamScoreImportExcelVO.builder()
                .examId(this.examId)
                .studentId(this.studentId)
                .classId(this.classId)
                .examNo(this.examNo)
                .studentName(this.studentName)
                .className(this.className)
                .subjectCombination(this.subjectCombination)
                .totalOriginalScore(this.totalOriginalScore != null ? this.totalOriginalScore : this.totalScore)
                .totalAssignedScore(this.totalScore)
                .totalUnionRank(this.totalUnionRank)
                .combinationRank(this.totalUnionSubjectRank)
                .schoolRank(this.schoolRank)
                .classRank(this.classRank)
                .chineseOriginalScore(this.chineseScore)
                .chineseUnionRank(this.chineseUnionRank)
                .chineseSchoolRank(this.chineseSchoolRank)
                .chineseClassRank(this.chineseClassRank)
                .mathOriginalScore(this.mathScore)
                .mathUnionRank(this.mathUnionRank)
                .mathSchoolRank(this.mathSchoolRank)
                .mathClassRank(this.mathClassRank)
                .englishOriginalScore(this.englishScore)
                .englishUnionRank(this.englishUnionRank)
                .englishSchoolRank(this.englishSchoolRank)
                .englishClassRank(this.englishClassRank)
                .physicsOriginalScore(this.physicsScore)
                .physicsUnionRank(this.physicsUnionRank)
                .physicsSchoolRank(this.physicsSchoolRank)
                .physicsClassRank(this.physicsClassRank)
                .chemistryOriginalScore(this.chemistryOriginalScore != null ? this.chemistryOriginalScore : this.chemistryScore)
                .chemistryAssignedScore(this.chemistryScore)
                .chemistryGradeLevel(this.chemistryGradeLevel)
                .chemistryUnionRank(this.chemistryUnionRank)
                .chemistrySchoolRank(this.chemistrySchoolRank)
                .chemistryClassRank(this.chemistryClassRank)
                .biologyOriginalScore(this.biologyOriginalScore != null ? this.biologyOriginalScore : this.biologyScore)
                .biologyAssignedScore(this.biologyScore)
                .biologyGradeLevel(this.biologyGradeLevel)
                .biologyUnionRank(this.biologyUnionRank)
                .biologySchoolRank(this.biologySchoolRank)
                .biologyClassRank(this.biologyClassRank)
                .politicsOriginalScore(this.politicsOriginalScore != null ? this.politicsOriginalScore : this.politicsScore)
                .politicsAssignedScore(this.politicsScore)
                .politicsGradeLevel(this.politicsGradeLevel)
                .politicsUnionRank(this.politicsUnionRank)
                .politicsSchoolRank(this.politicsSchoolRank)
                .politicsClassRank(this.politicsClassRank)
                .historyOriginalScore(this.historyScore)
                .historyUnionRank(this.historyUnionRank)
                .historySchoolRank(this.historySchoolRank)
                .historyClassRank(this.historyClassRank)
                .geographyOriginalScore(this.geographyOriginalScore != null ? this.geographyOriginalScore : this.geographyScore)
                .geographyAssignedScore(this.geographyScore)
                .geographyGradeLevel(this.geographyGradeLevel)
                .geographyUnionRank(this.geographyUnionRank)
                .geographySchoolRank(this.geographySchoolRank)
                .geographyClassRank(this.geographyClassRank)
                .build();
    }

    /**
     * 转换为ExamScoreImportExcelVO格式（兼容旧格式）
     */
    public ExamScoreImportExcelVO toExamScoreImportExcelVO() {
        return ExamScoreImportExcelVO.builder()
                .examId(this.examId)
                .studentId(this.studentId)
                .studentNo(this.getStudentNo())
                .studentName(this.studentName)
                .chineseScore(this.chineseScore)
                .mathScore(this.mathScore)
                .englishScore(this.englishScore)
                .physicsScore(this.physicsScore)
                .chemistryScore(this.chemistryScore)
                .biologyScore(this.biologyScore)
                .politicsScore(this.politicsScore)
                .historyScore(this.historyScore)
                .geographyScore(this.geographyScore)
                .totalScore(this.totalScore != null ? this.totalScore : this.totalOriginalScore)
                .build();
    }
}